import {createRouter,createWebHistory} from 'vue-router'

//导入组件
import xntz from "@/views/information/xntz.vue";
import xxgw from "@/views/information/xxgw.vue";
import xxlh from "@/views/information/xxlh.vue";
import xxxx from "@/views/information/xxxx.vue";
import {getStorage} from "@/utils/localStorage.js";
import {ElNotification} from "element-plus";


//定义路由关系
const routes = [
    {
      path: "/0",
      redirect: "/login",
    },
    {
        path: "/information/0",
        redirect: "/login",
    },
    {
        path: '/',
        redirect:'/login'
    }, {
        path: '/login',
        meta: {
            name: "登录注册页",
            requiresLogin: false,
        },
        component:() => import("@/views/Login.vue")
    }, {
        path:'/main',
        meta: {
            requiresLogin: true,
        },
        component:()=> import("@/views/Main.vue")
    }, {
        path: "/empty",
        component: () => import("@/components/empty.vue")
    }, {
        path: '/admission',
        component:() => import("@/views/admissionSystem/AdmissionView.vue"),
        meta: {
            name: "新生入学系统",
            requiresLogin: true
        },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    }, {
        path: '/dataCenter',
        component:() => import("@/views/dataCenter/DataCenterView.vue"),
        redirect: '/dataCenter/userDataView',
        meta: {
            name: "数据显示中心",
            requiresLogin: true
        },
        children:[
            //在这里添加该系统下的子页面
            {
                path: "/dataCenter/0",
                redirect: "/login",
            },
            {
                path: '/dataCenter/userDataView',
                component:() => import("@/views/dataCenter/components/UserDataView.vue")
            },{
                path: '/dataCenter/recruitDataView',
                component:() => import("@/views/dataCenter/components/RecruitDataView.vue")
            }, {
                path: '/dataCenter/reportingDataView',
                component:() => import("@/views/dataCenter/components/ReportingDataView.vue")
            },{
                path: '/dataCenter/dormitoryDataView',
                component:() => import("@/views/dataCenter/components/DormitoryDataView.vue")
            },{
                path: '/dataCenter/textbookDataView',
                component:() => import("@/views/dataCenter/components/TextbookDataView.vue")
            },{
                path: '/dataCenter/rpDataView',
                component:() => import("@/views/dataCenter/components/RPDataView.vue"),
                props: true
            },{
                path: '/dataCenter/testView',
                component:() => import("@/views/dataCenter/components/TestView.vue"),
                props: true
            }
        ]
    },{
        path: '/dormitoryManage',
        component:() => import("@/views/dormitoryManage/DormitoryManageView.vue"),
        redirect: '/aside/building',
        meta: {
            name: "宿舍管理系统",
            requiresLogin: true
        },
        children:[
            {
                path: "/aside/0",
                redirect: "/login",
            },
            {
            path: '/aside/building',
            component:() => import("@/views/dormitoryManage/aside/Building.vue")
        },{
            path: '/aside/room',
            component:() => import("@/views/dormitoryManage/aside/Room.vue")
        },{
            path: '/aside/student',
            component:() => import("@/views/dormitoryManage/aside/Student.vue")
        },{
            path: '/aside/out',
            component:() => import("@/views/dormitoryManage/aside/Out.vue")
        },{
            path: '/aside/payment',
            component:() => import("@/views/dormitoryManage/aside/Payment.vue")
        }]
    },{
        path: '/recruit',
        redirect: '/newPage',
        // component:() => import("@/views/recruitSystem/recruitView.vue"),
        // meta: {
        //     name: "招生管理系统"
        // },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    },{
        path: '/reporting',
        redirect: '/newPage',
        // component:() => import("@/views/reportingSystem/ReportingView.vue"),
        // meta: {
        //     name: "在校生报道管理系统",
        //     requiresLogin: true
        // },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    },{
        path: '/RPManage',
        redirect: '/newPage',
        // component:() => import("@/views/RPManage/RPManageView.vue"),
        // meta: {
        //     name: "奖惩管理",
        //     requiresLogin: true
        // },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    },{
        path: '/textbookManage',
        redirect: '/newPage',
        // component:() => import("@/views/textbookManage/TextbookManageView.vue"),
        // meta: {
        //     name: "教材管理"
        // },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    },{
        path: '/userManage',
        component:() => import("@/views/userManage/UserManageView.vue"),
        redirect: '/userManage/view/users',
        meta: {
            name: "用户权限管理",
            requiresLogin: true
        },
        children:[
            {
                path: "/userManage/view/0",
                redirect: "/login",
            },{
            path: '/userManage/view/users',
            component:() => import("@/views/userManage/components/TableView/UserTableView.vue")
        },{
            path: '/userManage/view/students',
            component:() => import("@/views/userManage/components/TableView/StudentTableView.vue")
        }, {
            path: '/userManage/view/freshman',
            component:() => import("@/views/userManage/components/TableView/FreshmanTableView.vue")
        },{
            path: '/userManage/view/counselors',
            component:() => import("@/views/userManage/components/TableView/CounselorTableView.vue")
        },{
            path: '/userManage/view/leaders',
            component:() => import("@/views/userManage/components/TableView/LeaderTableView.vue")
        },{
            path: '/userManage/userDetail/:userid',
            component:() => import("@/views/userManage/components/UserDetail.vue"),
            props: true
        }]
    },




    {//学生页面路由
        path: '/students',
        component:() => import("@/views/personalPortal/rolePortal/StudentsPortal.vue"),
        redirect: '/students/main',
        meta: {
            name: "学生门户中心"
        },
        children:[
            {
                path: "/students/0",
                redirect: "/login",
            },
            {//学生主页路由
            path: '/students/main',
            component:() => import("@/views/personalPortal/StudentsPage/Main.vue")
        },{//学生主页路由
            path: '/students/schedule',
            component:() => import("@/views/personalPortal/StudentsPage/Schedule.vue")
        },{//学生主页路由
            path: '/students/dormitory',
            component:() => import("@/views/personalPortal/StudentsPage/Dormitory.vue")
        }, {//学生主页路由
            path: '/students/textbook',
            component:() => import("@/views/personalPortal/StudentsPage/Textbook.vue")
        },{//学生主页路由
            path: '/students/award',
            component:() => import("@/views/personalPortal/StudentsPage/Award.vue")
        },{//学生主页路由
            path: '/students/fee',
            component:() => import("@/views/personalPortal/StudentsPage/Fee.vue")
        },
        ],
        mate:{
            breadList: [{
                name: "首页",
                path: "/main"
            }, {
                name: "课表",
                path: "/schedule"
            },
            ],
            requiresLogin: true
        }
    },



    {
        path: '/leaders',
        component: () => import("@/views/personalPortal/rolePortal/LeadersPortal.vue"),
        redirect: '/leaders/main',
        meta: {
            name: "领导门户",
            requiresLogin: true
        },
        children: [
            {
                path: "/leaders/0",
                redirect: "/login",
            },
            {//学生主页路由
                path: '/leaders/main',
                component: () => import("@/views/personalPortal/LeadersPage/Main.vue")
            },{//学生主页路由
                path: '/leaders/schedule',
                component:() => import("@/views/personalPortal/LeadersPage/Schedule.vue")
            },{//学生主页路由
                path: '/leaders/dormitory',
                component:() => import("@/views/personalPortal/LeadersPage/Dormitory.vue")
            }, {//学生主页路由
                path: '/leaders/award',
                component:() => import("@/views/personalPortal/LeadersPage/Award.vue")
            },{//学生主页路由
                path: '/leaders/fee',
                component:() => import("@/views/personalPortal/LeadersPage/Fee.vue")
            },
        ],
        mate: {
            breadList: [{
                name: "首页",
                path: "/main"
            }, {
                name: "课表",
                path: "/schedule"
            },
            ],
            requiresLogin: true
        }
    },


    {
        path: '/counselors',
        component:() => import("@/views/personalPortal/rolePortal/CounselorsPortal.vue"),
        meta: {
            name: "辅导员门户",
            requiresLogin: true
        },
        // children:[{
        //     //在这里添加该系统下的子页面
        // }]
    },


    {
        path: '/freshmen',
        component: () => import("@/views/personalPortal/rolePortal/FreshmenPortal.vue"),
        redirect: '/freshmen/main',
        meta: {
            name: "领导门户",
            requiresLogin: true
        },
        children: [
            {
                path: "/freshmen/0",
                redirect: "/login",
            },
            {//学生主页路由
                path: '/freshmen/main',
                component: () => import("@/views/personalPortal/FreshmenPage/Main.vue")
            },{//学生主页路由
                path: '/freshmen/schedule',
                component:() => import("@/views/personalPortal/FreshmenPage/Schedule.vue")
            },{//学生主页路由
                path: '/freshmen/dormitory',
                component:() => import("@/views/personalPortal/FreshmenPage/Dormitory.vue")
            }, {//学生主页路由
                path: '/freshmen/award',
                component:() => import("@/views/personalPortal/FreshmenPage/Award.vue")
            },{//学生主页路由
                path: '/freshmen/fee',
                component:() => import("@/views/personalPortal/FreshmenPage/Fee.vue")
            },
        ],
        mate: {
            breadList: [{
                name: "首页",
                path: "/main"
            }, {
                name: "课表",
                path: "/schedule"
            },
            ],
            requiresLogin: true
        }
    },
    {
        path: '/weather',
        component:() => import("@/views/WeatherView.vue"),
        meta: {
            name: "天气智能组件",
            requiresLogin: false
        },
    },
    {
        path: '/ai',
        component:() => import("@/views/AIView.vue"),
        meta: {
            name: "ai智能问答",
            requiresLogin: false
        },
    },
    {
        path:'/information/xntz',
        component:xntz,
        meta: {
            requiresLogin: false
        },
    },
    {
        path:'/information/xxgw',
        component:xxgw,
        meta: {
            requiresLogin: false
        },
    },
    {
        path:'/information/xxlh',
        component:xxlh,
        meta: {
            requiresLogin: false
        },
    },
    {
        path:'/information/xxxx',
        component:xxxx,
        meta: {
            requiresLogin: false
        },
    },
    {
        path: '/newPage',
        component:() => import("@/components/common/new.vue"),
        meta: {
            name: "新页面",
            requiresLogin: true
        },
    }
]

//创建路由器
const router = createRouter({
    history:createWebHistory(),
    routes:routes
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
    const token = getStorage('Token')
    const requiresLogin = to.matched.some(record => record.meta.requiresLogin); // 检查是否需要登录
    if (requiresLogin && token === null) {

        // 如果需要登录但用户未登录，则重定向到登录页面
        ElNotification({
            title: '用户未登录',
            message: "请先登录系统",
            type: 'warning',
        })
        next('/login');
    } else {
        next();
    }
});

//导出路由
export default router
